import houseOpt from '@/biz/option/house.js'
import toolMgr from '@/biz/base/tool.js'
import ruleOpt from '@/biz/option/rule.js'
import dt from '@dt/dt'

let _this = null

function options(vm) {
  _this = vm

  let attaches = {
    title: '回单附件',
    key: 'attaches',
    placeholder: '回单附件上传后才可进行核销操作',
    upload: {
      title: '上传文件',
      api: toolMgr.unloadFile(),
      files: [],
      multiple: true
    },
    data: {
      to: (v) => {
        return {
          attaches: v.map((item) => ({
            fileName: item.name,
            attachAddress: item.response ? item.response.data.imageURL : item.url
          }))
        }
      }
    }
  }

  if (_this.backId) {
    attaches.rules = [ruleOpt.required('请上传回单附件', 'array')]
    return [attaches]
  }

  return [
    houseOpt.create({
      to: (info) => {
        return {
          housesId: info.housesId
        }
      }
    }),
    {
      title: '回款金额',
      placeholder: '请输入回款金额',
      key: 'backAmount',
      input: {
        type: 'number'
      },
      rules: [ruleOpt.required('请输入回款金额', 'number')]
    },
    {
      title: '回款类型',
      placeholder: '请选择回款类型',
      key: 'backType',
      radio: {
        options: dt.dictInfo().backType
      },
      rules: [ruleOpt.required('请选择回款类型')]
    },
    {
      title: '回款日期',
      placeholder: '请选择回款日期',
      key: 'backDate',
      date: {},
      rules: [ruleOpt.required('请选择奖请选择回款日期金单年份')]
    },
    attaches,
    {
      title: '备注',
      key: 'remark',
      input: {
        type: 'textarea',
        autosize: {
          minRows: 4
        }
      }
    }
  ]
}

export default {
  options
}
